﻿/// <reference path="JSintellisense/jquery-1.3.2-vsdoc2.js" />
var map = null;
var geocoder = null;
var marker = null;
var center = null;
var lat_lng_all = "";
var latlng_array = null;
var gzoom = 17;
var myadd = "";
var mylabel = null;
var adds = null;

function initialize() {
    var _lat = parseFloat($("#lat").val());
    var _lng = parseFloat($("#lng").val());
    if (_lat == "0" || _lng == "0") {
        return;
    }

    map = new BMap.Map("map_canvas");
    map.enableScrollWheelZoom();

    mylabel = new BMap.Label("配送员", { offset: new BMap.Size(0, -22) });
    mylabel.setStyle({ color: "blue", fontSize: "12px", padding: "2px 5px 2px 5px" });

    center = new BMap.Point(_lng, _lat);

    //配送员位置
    marker = new BMap.Marker(center, { title: '配送员' });
    map.addOverlay(marker);
    marker.enableDragging();
    map.addControl(new BMap.NavigationControl());
    marker.setLabel(mylabel);

    map.centerAndZoom(center, gzoom);

    var _latlng = $("#hflatlng").val();

    if (_latlng != "") {
        jsonlatlng = eval("(" + _latlng + ")");
        //用户坐标
        var userlabel = new BMap.Label("我", { offset: new BMap.Size(0, -22) });
        userlabel.setStyle({ color: "blue", fontSize: "12px", padding: "2px 5px 2px 5px" });
        var userpoint = new BMap.Point(jsonlatlng.ulng, jsonlatlng.ulat);
        var usermarker = new BMap.Marker(userpoint);
        usermarker.setLabel(userlabel);

        map.addOverlay(usermarker);

        //商家坐标
        var userlabel = new BMap.Label($("#hfshopname").val(), { offset: new BMap.Size(0, -22) });
        userlabel.setStyle({ color: "blue", fontSize: "12px", padding: "2px 5px 2px 5px" });
        var userpoint = new BMap.Point(jsonlatlng.slng, jsonlatlng.slat);
        var usermarker = new BMap.Marker(userpoint);
        usermarker.setLabel(userlabel);

        map.addOverlay(usermarker);

    }
}

function setLatLng(point) {
    document.getElementById("lat").value = point.lat;
    document.getElementById("lng").value = point.lng;
    return true;
}

//定位相关类
$(function () {
    initialize();
})
